﻿@using Lib.core;
@using Lib.helper;

@using Bll;
@using Model.Category;
@using Lib.model;
@{
    Layout = null;
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- header page -->
    @Html.Partial(IncludePath("header"))
</head>

<body>
    @Html.Partial(IncludePath("body_top"))

    <div class="container-fluid">

        <div class="row">

            @{
                var model = ViewData["model"] as CategoryModel;
                if (model == null) { model = new CategoryModel(); }
            }

            <div class="col-md-12">
                <form id="fm">
                    <table class="table">
                        <thead>
                            <tr>
                                <td style="width:20%;"></td>
                                <td style="width:80%;"></td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="active">名称</td>
                                <td>
                                    <input type="hidden" name="id" value="@(model.CategoryID)" />
                                    <input type="hidden" name="type" value="@(model.CategoryType)" />
                                    <input type="text" class="form-control" name="name" value="@(model.CategoryName)" />
                                </td>
                            </tr>
                            <tr>
                                <td class="active">描述</td>
                                <td>
                                    <input type="text" class="form-control" name="desc" value="@(model.CategoryDescription)" />
                                </td>
                            </tr>
                            <tr>
                                <td class="active">链接</td>
                                <td>
                                    <input type="text" class="form-control" name="link" value="@(model.LinkURL)" />
                                </td>
                            </tr>
                            <tr>
                                <td class="active">图标地址</td>
                                <td>
                                    <input type="text" class="form-control" name="img" value="@(model.CategoryImage)" />
                                </td>
                            </tr>
                            <tr>
                                <td class="active">图标class</td>
                                <td>
                                    <input type="text" class="form-control" name="icon" value="@(model.IconClass)" />
                                </td>
                            </tr>
                            <tr>
                                <td class="active">新窗口打开</td>
                                <td>
                                    <select class="form-control" name="target" data-value="@(model.OpenInNewWindow)">
                                        <option value="false" selected="selected">否</option>
                                        <option value="true">是</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td class="active">排序</td>
                                <td>
                                    <input type="number" class="form-control" name="order" value="@(model.OrderNum)" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>

            <div class="col-md-12">
                <div class="pull-left">
                    <button class="btn btn-info" id="add_same">保存到同级</button>
                    <button class="btn btn-success" id="add_child">保存到下级</button>
                </div>
                <div class="pull-right">
                    <button class="btn btn-x" id="del">删除</button>
                    <button class="btn btn-primary" id="update">保存</button>
                </div>
            </div>

        </div>

        <script type="text/javascript">

            $(function () {

                //获取输入数据
                function getData() {
                    return $('#fm').serializeArray();
                }

                //删除节点
                $('#del').click(function () {
                    var model = getData();
                    if (model == null) { return; }
                    if (!confirm('将永久删除其下所有子节点，请谨慎操作')) { return; }
                    postJson('/admin/category/DeleteNode/', model, function (json) {
                        if (json.success) {
                            reload_parent();
                        }
                        else {
                            alert(json.msg);
                        }
                    });
                });
                //添加到同一级
                $('#add_same').click(function () {
                    var model = getData();
                    if (model == null) { return; }
                    postJson('/admin/category/AddSameLevel/', model, function (json) {
                        if (json.success) {
                            reload_parent();
                        }
                        else {
                            alert(json.msg);
                        }
                    });
                });
                //添加到子集
                $('#add_child').click(function () {
                    var model = getData();
                    if (model == null) { return; }
                    postJson('/admin/category/AddChildLevel/', model, function (json) {
                        if (json.success) {
                            reload_parent();
                        }
                        else {
                            alert(json.msg);
                        }
                    });
                });
                //更新节点
                $('#update').click(function () {
                    var model = getData();
                    if (model == null) { return; }
                    postJson('/admin/category/UpdateNode/', model, function (json) {
                        if (json.success) {
                            reload_parent();
                        }
                        else {
                            alert(json.msg);
                        }
                    });
                });
            });
        </script>

    </div>

</body>
</html>
